package com.justerdu.mvpclient.user.presenter;

import android.content.Context;

import com.justerdu.mvpclient.user.model.dao.IUserDao;
import com.justerdu.mvpclient.user.model.dao.UserDao;
import com.justerdu.mvpclient.user.model.domain.User;

import java.util.List;

/**
 * @Author JusterDu 2016/11/21.
 * @Func
 */
public class UserService implements IUserService {

    private IUserDao userDao;

    public UserService(Context context){
        userDao = new UserDao(context);
    }
    @Override
    public Boolean addUser(User user) {
        try{
            userDao.save(user);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public Boolean deleteUser(Integer id) {
        try{
            userDao.delete(id);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public Boolean editUser(User user) {
        try{
            userDao.update(user);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public User findUserById(Integer id){
        return userDao.findUserById(id);
    }

    @Override
    public List<User> findAllUser() {
        return userDao.findAll();
    }

    public IUserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(IUserDao userDao) {
        this.userDao = userDao;
    }
}
